<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@include file="/WEB-INF/jsp/common/navigationRight.jsp" %>
<%@include file="/WEB-INF/jsp/common/head.jsp" %>
<%@include file="/WEB-INF/jsp/common/navigationLeft.jsp" %>

<div class="m2-userCentersettings-con">
  <form>
      <%--存放userId的隐藏域--%>
      <input type="hidden" name="id" value="${userSession.userId}" />
    <!--您现在的安全级别-->
    <div class="m2-userCentersettings-bg">
        <div class="m2-wel-level m2-userSettings-level">
            <div class="m2-level-image">
                <b class="m2-wel-levelTip">您现在的安全级别</b>
                <b class="m2-userSettingslevel-low" id='safe_level'></b>
                <i class="m2-levelIcon-fal"></i>
                <i class="m2-levelIcon-fal"></i>
                <i class="m2-levelIcon-fal"></i>
                <b class="m2-wel-levelTip">请通过完善下方信息来提升安全级别</b>
            </div>
        </div>
        <ul>
            <li class="m2-userCentersettings-step1 m2-userSettings-step">
                <div class="m2-userSettings-stepShow">
                    <i></i>
                    <span class="m2-userSettingsshow-tit m2-userSettingsshow-tit2">手机号码</span>
                    <span class="m2-userSettingsshow-exp">爱钱帮会通过手机号发送各类短信，验证手机号会更加便捷</span>
                    <span class="m2-userSettingsaut m2-userSettingsaut-fal" id='phone_status'><b></b>未绑定</span>
                    <span class="m2-userSettingsshow-link"><a href="javascript:void(0)">添加</a></span>
                </div>

                <ul class="m2-userSettings-setpHide" style="display:none;" id='phone_status_1'>
                    <!-- 						<li class="m2-userSettingshide-tit"> -->
                    <!-- 							可添加说明文字可添加说明文字可添加说明文字 -->
                    <!-- 						</li> -->

                    <li>
                        <span class="m2-userSettingshide-nor"><u>*</u>手机号：</span>
                        <input type="text" placeholder="请输新手机号码" type="text" id='vp-phonenum' value="${userSession.phone}">
                        <a class="m2-userSettings-telSubmit" href="javascript:void(0)" id='vp-textbtn'>短信验证码</a>
                        <a class="m2-userSettings-telSubmit" href="javascript:void(0)" id='vp-voicebtn'>语音验证码</a>
                        <span class="m2-userSettingshide-warning"
                              style='margin-left: 80px;margin-top: 10px;display: none;' id='vp-warn'><em></em>请输入正确的手机号。</span>
                        <span class="m2-userSettingshide-success m2-userSettingshide-successTel" style='display: none'
                              id='vp-msg'><em></em>验证码已发出,如果您在2分钟之内未收到验证码,请再次获取验证码</span>
                    </li>
                    <li style="display:none;" id='verifyphoneli'>
                        <span class="m2-userSettingshide-nor"><u>*</u>验证图码：</span>
                        <input type="text" placeholder="请输入图片验证码" type="text" id='vp-vpic'>
                        <img src="code.png" width="104" height="42" style="cursor: pointer"
                             onclick="document.getElementById('reverifyCode').src='code.png?time='+Math.random();void(0);"
                             id="reverifyCode"/>
                        <span class="m2-userSettingshide-warning"></span>
                    </li>
                    <li>
                        <span class="m2-userSettingshide-nor"><u>*</u>验证码：</span>
                        <input type="text" placeholder="请输入收到的验证码" type="text" id='vp-text'>
                    </li>
                    <li class="m2-userSettingshide-btn"><a href="javascript:void(0)" id='vp-submit'>修改</a></li>
                </ul>
            </li>
            <li class="m2-userCentersettings-step2 m2-userSettings-step">
                <div class="m2-userSettings-stepShow">
                    <i></i>
                    <span class="m2-userSettingsshow-tit m2-userSettingsshow-tit2">徽商存管账户</span>
                    <span class="m2-userSettingsshow-exp">投资合同需要实名签署，实名合同才有法律效应，爱钱帮通过徽商银行完成实名认证</span>
                    <span class="m2-userSettingsaut m2-userSettingsaut-fal" id='id_status'><b></b>未认证</span>
                    <span class="m2-userSettingsshow-link"><a href="home-register-openbankid.html"
                                                              target="_blank">认证</a></span>
                </div>
            </li>
            <li class="m2-userCentersettings-step3 m2-userSettings-step">
                <div class="m2-userSettings-stepShow">
                    <i></i>
                    <span class="m2-userSettingsshow-tit">徽商交易密码</span>
                    <span class="m2-userSettingsshow-exp">交易密码需跳转徽商交易系统页面输入，适用于投资验证及提现验证
						</span>
                    <span class="m2-userSettingsaut m2-userSettingsaut-fal"><b></b>未开户</span>
                    <span class="m2-userSettingsshow-link"><a href="home-register-openbankid.html">开户</a></span></div>
                <ul class="m2-userSettings-setpHide" style="display:none;" id=''>
                    <li>
                        <input type="text" placeholder="请输手机号码" type="text" style="display:none";  readonly
                        id='hsvp-phonenum' value="13737301354">
                        <span class="m2-userSettingshide-nor"><u>*</u>手机验证码：</span>
                        <input type="text" placeholder="请输手机验证码" type="text" id='hs_code'>
                        <a class="m2-userSettings-telSubmit" href="javascript:void(0)" id='hsvp-textbtn'>短信验证码</a>
                    </li>
                    <li>
                        <span class="m2-userSettingshide-nor"><u>*</u>姓名：</span>
                        <input type="text" placeholder="请输入您的姓名" type="text" id="hs_name">
                        <span class="m2-userSettingshide-warning"></span>
                    </li>
                    <li>
                        <span class="m2-userSettingshide-nor"><u>*</u>身份证：</span>
                        <input type="text" placeholder="请输入您的身份证号码" type="text" id="hs_idCard">
                        <span class="m2-userSettingshide-warning"></span>
                    </li>
                    <li class="m2-userSettingshide-btn"><a href="javascript:void(0)" id='hsChange-btn'>下一步</a></li>
                </ul>

            </li>

            <li class="m2-userCentersettings-step4 m2-userSettings-step">
                <div class="m2-userSettings-stepShow">
                    <i></i>
                    <span class="m2-userSettingsshow-tit">电子邮箱</span>
                    <span class="m2-userSettingsshow-exp">获取最新的投资讯息和账户信息变动通知</span>
                    <span class="m2-userSettingsaut m2-userSettingsaut-fal" id='email_status'><b></b>未认证</span>
                    <span class="m2-userSettingsshow-link"><a href="javascript:void(0)">认证</a></span>
                </div>
                <ul class="m2-userSettings-setpHide" style="display:none;" id='email_status_2'>
                    <li class="m2-userSettingshide-tit">
                        请填写您的电子邮箱，点击下面的按钮发送激活邮件，登陆您的电子邮箱，完成验证。
                    </li>
                    <li>
                        <span class="m2-userSettingshide-nor"><u>*</u>邮箱：</span>
                        <input type="text" placeholder="请输入邮箱地址" type="text" value="${userSession.email}" id="verifyemail">
                        <span class="m2-userSettingshide-warning"></span>
                    </li>
                    <li class="m2-userSettingshide-btn"><a href="javascript:void(0)" id='verifyemail-btn'>发送验证邮件</a>
                    </li>
                </ul>
            </li>
            <li class="m2-userCentersettings-step5 m2-userSettings-step">
                <div class="m2-userSettings-stepShow">
                    <i></i>
                    <span class="m2-userSettingsshow-tit">联系地址</span>
                    <span class="m2-userSettingsshow-exp">用于邮寄资料或礼品</span>
                    <span class="m2-userSettingsaut m2-userSettingsaut-fal" id='address_status'><b></b>未添加</span>
                    <span class="m2-userSettingsshow-link"><a href="javascript:void(0)">添加</a></span>
                </div>

                <ul class="m2-userSettings-setpHide">
                    <li>
                        <span class="m2-userSettingshide-nor"><u>*</u>收货人：</span>
                        <input type="text" placeholder="长度不超过25个字符" name="consignee" id="addr_consignee"
                               class="addr_info" type="text" style='width: 350px;' value="">
                        <span class="m2-userSettingshide-warning"></span>
                    </li>
                    <li>
                        <span class="m2-userSettingshide-nor"><u>*</u>省市区：</span>
                        <select id="lmkselect1" name="province" style="width:140px;height:30px;">
                            <option data="all" class="all">请选择</option>
                        </select>
                        <select id="lmkselect2" name="city" id="addr_city" disabled="true"
                                style="width:120px;height:30px;">
                            <option data="all" class="all">请选择</option>
                        </select>
                        <select id="lmkselect3" name="area" id="addr_area" disabled="true"
                                style="width:120px;height:30px;">
                            <option data="all" class="all">请选择</option>
                        </select>
                        <span class="m2-userSettingshide-warning"></span>
                    </li>
                    <li>
                        <span class="m2-userSettingshide-nor"><u>*</u>详细地址：</span>
                        <input type="text" placeholder="请填写详细收货地址" id="addr_address" class="addr_info" type="text"
                               style='width: 350px;' value="">
                        <span class="m2-userSettingshide-warning"></span>
                    </li>
                    <li>
                        <span class="m2-userSettingshide-nor"><u>*</u>手机号码：</span>
                        <input type="text" name='phone' id="addr_phone" class="addr_info" placeholder="请填写收货人的手机号码"
                               type="text" style='width: 350px;' value="">
                        <span class="m2-userSettingshide-warning"></span>
                    </li>
                    <li class="m2-userSettingshide-btn"><a href="javascript:void(0)" id='newaddress-btn'>确认</a></li>
                </ul>
            </li>

            <li class="m2-userCentersettings-step6 m2-userSettings-step">
                <div class="m2-userSettings-stepShow">
                    <i></i>
                    <span class="m2-userSettingsshow-tit">登录密码</span>
                    <span class="m2-userSettingsshow-exp">上次登录时间：</span>
                    <span class="m2-userSettingsaut m2-userSettingsaut-tur"><b></b>已设置</span>
                    <span class="m2-userSettingsshow-link"><a href="javascript:void(0)">修改</a></span>
                </div>
                <ul class="m2-userSettings-setpHide">
                    <li>
                        <span class="m2-userSettingshide-nor"><u>*</u>原密码：</span>
                        <input type="password" placeholder="请输入原密码" type="text" id='oldpass' value="${userSession.password}">
                        <span class="m2-userSettingshide-warning"></span>
                    </li>
                    <li>
                        <span class="m2-userSettingshide-nor"><u>*</u>新密码：</span>
                        <input type="password" placeholder="请输入新密码" type="text" id='newpass1'>
                        <span class="m2-userSettingshide-warning"></span>
                    </li>
                    <li>
                        <span class="m2-userSettingshide-nor"><u>*</u>确认密码：</span>
                        <input type="password" placeholder="请再次输入新密码" type="text" id='newpass2'>
                        <span class="m2-userSettingshide-warning"></span>
                    </li>
                    <li class="m2-userSettingshide-btn"><a href="javascript:void(0)" id='setpass-btn'>确认</a></li>
                </ul>
            </li>
            <li class="m2-userCentersettings-step7 m2-userSettings-step">
                <div class="m2-userSettings-stepShow">
                    <i></i>
                    <span class="m2-userSettingsshow-tit">用户名修改</span>
                    <span class="m2-userSettingsshow-exp">你可以通过此功能修改用户名</span>
                    <span class="m2-userSettingsaut m2-userSettingsaut-tur"><b></b>未修改</span>
                    <span class="m2-userSettingsshow-link"><a href="javascript:void(0)">修改</a></span>
                </div>

                <ul class="m2-userSettings-setpHide">
                    <li class="m2-userSettingshide-tit">用户名只允许字母、数字、下划线组成，首位只能为字母，且至少需要 6 个字符。</li>
                    <li>
                        <span class="m2-userSettingshide-nor">用户名：</span><input placeholder="请输入用户名" type="text"
                                                                                id='usernametext' value="${userSession.userCode}">
                        <span class="m2-userSettingshide-warning" id='usernamewarn'></span>
                    </li>
                    <li class="m2-userSettingshide-btn"><a href="/user/modify?userId=${userSession.userId}" onclick='changeUserName()'>修改</a>
                    </li>
                </ul>
            </li>
        </ul>
    </div>
  </form>
</div>
<script type="text/javascript" src="/statics/statics/common/js/jquery.js"></script>
<script type="text/javascript" src="/statics/statics/home2/js/HMZCity.json?20160520"></script>
<script type="text/javascript">
    $(function () {
        $user_type = 1;
        //点击修改按钮展开选项
        $('.m2-userSettings-setpHide').hide();
        $('.m2-userSettingsshow-link a').click(function () {
            $(this).parents('.m2-userSettings-stepShow').siblings('.m2-userSettings-setpHide').toggle(500);
        });
        setVerifyStatus();
        bindphone();
        setPassword();
        setAddress();
        verifyemail();
        getQuestionnaire();
        hsChangePassWord();

        function getQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) {
                return unescape(r[2]);
            }
            return null;
        }


        var xl = getQueryString("isXl");
        if (xl == "1") {
            $("#hsmmsz").trigger("click");
        }
        var xg = getQueryString("isXg");
        if (xg == "1") {
            $("#hsmmxg").trigger("click");
        }
    });

    function setVerifyStatus() {

        var id_status = 0;
        var address_status = 0;
        var email_status = 0;
        var phone_status = 1;
        var questionnaire_status = 0;
        var setword_status = 0;
        var i = Number(id_status) + Number(phone_status) + Number(email_status);

        if (i == 1) {
            $('#safe_level').text('低');
        } else if (i == 2) {
            $('#safe_level').text('中');
        } else if (i == 3) {
            $('#safe_level').text('高');
        } else {
            $('#safe_level').text('极低');
        }
        var j = 0;
        $('.m2-levelIcon-fal').each(function () {
            if (j < i) {
                $(this).prop('class', 'm2-levelIcon-tur');
                j++;
            }
        });
        if (id_status == 1) {
            $('#id_status').removeClass('m2-userSettingsaut-fal');
            $('#id_status').addClass('m2-userSettingsaut-tur');
            $('#id_status').html('<b></b>已认证');
            $('#id_status').next('span').find('a').text('查看');
            $('#id_status').next('span').find('a').prop('href', '#');
            $('#tid_status').removeClass('m2-userSettingsaut-fal');
            $('#tid_status').addClass('m2-userSettingsaut-tur');
            $('#tid_status').html('<b></b>已认证');
            $('#tid_status').next('span').find('a').text('查看');
            $('#tid_status').next('span').find('a').prop('href', '#');
        }
        if (phone_status == 1) {
            $('#phone_status').removeClass('m2-userSettingsaut-fal');
            $('#phone_status').addClass('m2-userSettingsaut-tur');
            $('#phone_status').html('<b></b>已绑定');
            $('#phone_status').next('span').find('a').text('修改');
            $('#phone_status_2').remove();
            if (3 < 0) {
                $('#verifyphoneli').show();
            }
        }
        if (3 < 0) {
            $('#verifyphoneli').show();
        }
        if (email_status == 1) {
            $('#email_status').removeClass('m2-userSettingsaut-fal');
            $('#email_status').addClass('m2-userSettingsaut-tur');
            $('#email_status').html('<b></b>已验证');
            $('#email_status').next('span').find('a').text('修改');
        }
        if (address_status == 1) {
            $('#address_status').removeClass('m2-userSettingsaut-fal');
            $('#address_status').addClass('m2-userSettingsaut-tur');
            $('#address_status').html('<b></b>已添加');
            $('#address_status').next('span').find('a').text('修改');
        }
        if (questionnaire_status == 1) {
            $('#questionnaire_status').removeClass('m2-userSettingsaut-fal');
            $('#questionnaire_status').addClass('m2-userSettingsaut-tur');
            $('#questionnaire_status').html('<b></b>已填写');
            $('#questionnaire_status').next('span').find('a').text('查看');
            $('#questionnaire-text').text('因时制宜，期待每一次改变');
            $('.question_subbtn').hide();
        }
        if (getParam('phone') == 1) {
            $('#phone_status').next('span').find('a').click();
        }
        if (getParam('email') == 1) {
            $('#email_status').next('span').find('a').click();
        }
        if (getParam('hspassword') == 1) {
            $('#email_status').next('span').find('a').click();
        }
    }

    function bindphone() {

        var flag = false;
        var t1 = 0, t2 = 0;
        var reg = /^1\d{10}$/;

        if (reg.test($('#vp-phonenum').val())) {
            flag = true;
        } else {
            flag = false;
        }
        $('#vp-phonenum').keyup(function () {
            if (reg.test($('#vp-phonenum').val())) {
                $('#vp-warn').hide();
                flag = true;
            } else {
                $('#vp-warn').show();
                flag = false;
            }
        });
        $('#vp-textbtn').click(function () {
            t2 = Date.now();
            if (t2 - t1 > 60 * 1000 && flag) {
                t1 = Date.now();
                $.ajax({
                    url: "/usercenter-Accountcontrol-sendphone",
                    type: "POST",
                    data: {
                        cellphone: $('#vp-phonenum').val(),
                        vcode: $('#vp-vpic').val()
                    },
                    success: function (data) {
                        var obj = eval('(' + data + ')');
                        if (obj.status == 2) {
                            $('#vp-msg').show();
                            dialog(obj);
                        } else {
                            dialog(obj);
                        }
                    }
                });
                if ($(this).hasClass('m2-userSettings-telSubmit')) {
                    $(this).removeClass('m2-userSettings-telSubmit');
                    $(this).addClass('m2-userSettings-telSubmit-disabled');
                    setTimeout(function () {
                        $('#vp-textbtn').removeClass('m2-userSettings-telSubmit-disabled');
                        $('#vp-textbtn').addClass('m2-userSettings-telSubmit');
                        $('#vp-msg').hide();
                    }, 60000);
                }
            }
        });
        $('#vp-voicebtn').click(function () {
            t2 = Date.now();
            if (t2 - t1 > 60 * 1000 && flag) {
                t1 = Date.now();
                $.ajax({
                    url: "/usercenter-Accountcontrol-sendvoice",
                    type: "POST",
                    data: {
                        cellphone: $('#vp-phonenum').val(),
                        vcode: $('#vp-vpic').val()
                    },
                    success: function (data) {
                        obj = eval('(' + data + ')');
                        if (obj.status == 2) {
                            $('#vp-msg').show();
                            dialog(obj);
                        } else {
                            dialog(obj);
                        }
                    }
                });
                if ($(this).hasClass('m2-userSettings-telSubmit')) {
                    $(this).removeClass('m2-userSettings-telSubmit');
                    $(this).addClass('m2-userSettings-telSubmit-disabled');
                    setTimeout(function () {
                        $('#vp-voicebtn').removeClass('m2-userSettings-telSubmit-disabled');
                        $('#vp-voicebtn').addClass('m2-userSettings-telSubmit');
                        $('#vp-msg').hide();
                    }, 60000);
                }
            }
        });
        $('#vp-submit').click(function () {
            if (flag) {
                t1 = Date.now();
                $.ajax({
                    url: "/usercenter-Accountcontrol-verifyPhone",
                    type: "POST",
                    data: {
                        cellphone: $('#vp-phonenum').val(),
                        code: $('#vp-text').val()
                    },
                    success: function (data) {
                        obj = eval('(' + data + ')');
                        dialog(obj);
                    }
                });
            }
        });
    }

    function setAddress() {

        var flag = false;

        $('.addr_info').keyup(function () {
            var addrMsg = $(this).attr('id');
            var addrMsgValue = $(this).val();
            if (addrMsg == 'addr_consignee') {
                if (isNaN(addrMsgValue)) {
                    $(this).next('span').html('');
                    flag = true;
                } else {
                    $(this).next('span').html('<em></em>收货人格式不正确。');
                    flag = false;
                }
            } else if (addrMsg == 'addr_address') {
                if (isNaN(addrMsgValue)) {
                    $(this).next('span').html('');
                    flag = true;
                } else {
                    $(this).next('span').html('<em></em>请输入正确的地址。');
                    flag = false;
                }
            } else if (addrMsg == 'addr_phone') {
                re = /^1\d{10}$/;
                if (re.test(addrMsgValue)) {
                    $(this).next('span').html('');
                    flag = true;
                } else {
                    $(this).next('span').html('<em></em>请输入正确的手机号。');
                    flag = false;
                }
            }
        });

        $('#newaddress-btn').click(function () {
            if ($("#lmkselect1 option:selected").attr("data") == 'all') {
                return false;
            }
            if ($("#lmkselect2 option:selected").attr("data") == 'all') {
                return false;
            }
            if ($("#lmkselect3 option:selected").attr("data") == 'all') {
                return false;
            }
            if (flag) {
                $.ajax({
                    url: "/usercenter-Accountcontrol-setAddress",
                    type: "POST",
                    data: {
                        addr_consignee: $('#addr_consignee').val(),
                        addr_province: $("#lmkselect1 option:selected").text(),
                        addr_city: $("#lmkselect2 option:selected").text(),
                        addr_area: $("#lmkselect3 option:selected").text(),
                        addr_address: $('#addr_address').val(),
                        addr_phone: $('#addr_phone').val()
                    },
                    success: function (data) {
                        obj = eval('(' + data + ')');
                        dialog(obj);
                    }
                });
            }
        });
    }


    function setPassword() {

        var flag1 = false;
        var flag2 = false;
        var flag3 = false;

        $('#oldpass').keyup(function () {
            if ($('#oldpass').val().length > 5 && $('#oldpass').val().length < 16) {
                $('#oldpass').next('span').html('');
                flag1 = true;
            } else {
                $('#oldpass').next('span').html('<em></em>密码需为6-15常用英文字母或数字。');
                flag1 = false;
            }
        });
        $('#newpass1').keyup(function () {
            if ($('#newpass1').val().length > 5 && $('#newpass1').val().length < 16) {
                $('#newpass1').next('span').html('');
                flag2 = true;
            } else {
                $('#newpass1').next('span').html('<em></em>密码需为6-15常用英文字母或数字。');
                flag2 = false;
            }
        });
        $('#newpass2').keyup(function () {
            if ($('#newpass2').val() == $('#newpass1').val()) {
                $('#newpass2').next('span').html('');
                flag3 = true;
            } else {
                $('#newpass2').next('span').html('<em></em>两次输入密码须一致！');
                flag3 = false;
            }
        });
        $('#setpass-btn').click(function () {

            if (flag1 && flag2 && flag3) {
                $.ajax({
                    url: "/usercenter-Accountcontrol-setPassWord",
                    type: "POST",
                    data: {
                        oldpass: $('#oldpass').val(),
                        newpass: $('#newpass2').val()
                    },
                    success: function (data) {
                        obj = eval('(' + data + ')');
                        dialog(obj);
                        $('#oldpass').val('');
                        $('#newpass1').val('');
                        $('#newpass2').val('');
                    }
                });
            }
        });
    }

    function verifyemail() {

        var flag = false;
        var reg = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;

        if (reg.test($('#verifyemail').val())) {
            flag = true;
        } else {
            flag = false;
        }

        $('#verifyemail').keyup(function () {
            if (reg.test($('#verifyemail').val())) {
                $('#verifyemail').next('span').html('');
                flag = true;
            } else {
                $('#verifyemail').next('span').html('<em></em>请输入正确的邮箱地址！');
                flag = false;
            }
        });

        $('#verifyemail-btn').click(function () {
            if (flag) {
                $.ajax({
                    url: "/usercenter-Accountcontrol-sendEmail",
                    type: "POST",
                    data: {
                        user_email: $('#verifyemail').val()
                    },
                    success: function (data) {
                        obj = eval('(' + data + ')');
                        dialog(obj);
                    }
                });
            }
        });
    }

    //问卷调查
    function getQuestionnaire() {

        $('#questionnaire-btn').click(function () {
            var anwser = '';
            var flag = true;
            $('#questionnaire ul').each(function () {
                if ($(this).find('input:checked').size() == 0) {
                    flag = false;
                    var obj = {};
                    obj['status'] = 0;
                    obj['msg'] = '您需要填写全部问题才能提交';
                    dialog(obj);
                    return;
                }
            });
            $('#questionnaire li').has('ul').each(function () {
                $(this).find('input').each(function () {
                    if ($(this).prop("checked")) {
                        anwser += $(this).next('label').text().substr(0, 1) + ':';
                    }
                });
                anwser += ',';
            });
            if (flag) {
                $.ajax({
                    url: "/usercenter-Accountcontrol-setQuestionnaire",
                    type: "POST",
                    data: {
                        anwser: anwser
                    },
                    success: function (data) {
                        obj = eval('(' + data + ')');
                        dialog(obj);
                    }
                });
            }
        });

        oldanwser = '';
        anwserobj = oldanwser.split(',');
        $('#questionnaire li').has('ul').each(function (i) {
            if (anwserobj[i]) {
                var subanwser = anwserobj[i].split(':');
                $(this).find('input').each(function () {
                    for (var j in subanwser) {
                        if (subanwser[j] == $(this).next('label').text().substr(0, 1)) {
                            $(this).prop("checked", "checked");
                        }
                    }
                });
            }
        });


    }

    function closeDialog() {
        $('.m2-userCentercommon-confirm').hide();
        $('.m2-userCentercommon-bg').hide();
    }

    function dialog(obj) {
        var dom = '<span class="m2-userCentercommon-confirmClose" onclick="closeDialog()"></span>';
        if (obj['status'] == 1 || obj['status'] == 2) {
            dom += '<p class="m2-userCommon-confirmSuc"><i></i>';
        } else {
            dom += '<p class="m2-userCommon-confirmWar"><i></i>';
        }
        if (obj['msg']) {
            dom += obj['msg'] + '</p>';
        } else if (obj['message']) {
            dom += obj['message'] + '</p>';
        } else {
            return;
        }
        if (obj['status'] == 1) {
            dom += '<p class="m2-userCommon-confirmBtn"><a class="m2-user-confirmBtn" onclick="window.location.reload();">确&nbsp;定</a></p>';
        } else if (obj['status'] == 2) {
            dom += '<p class="m2-userCommon-confirmBtn"><a class="m2-user-confirmBtn" onclick="closeDialog()">确&nbsp;定</a></p>';
        } else {
            dom += '<p class="m2-userCommon-confirmBtn"><a class="m2-user-confirmBtn" onclick="closeDialog()">确&nbsp;定</a></p>';
        }
        $('.m2-userCentercommon-confirm').html(dom);
        $('.m2-userCentercommon-confirm').show();
        $('.m2-userCentercommon-bg').show();
    }

    //修改用户名
    function changeUserName() {

        var userCode = $('#usernametext').val().trim();
        if (!userNameCheck(userCode)) {
            return;
        }
        $.ajax({
            url: "/user/modify",
            type:"get",
            dataType:"json",
            data: {"userCode": userCode},
            success: function (data) {
                var obj = eval('(' + data + ')');
                if (obj['success']) {
                    obj['status'] = 1;
                    dialog(obj);
                } else {
                    userNameWarn(obj['msg']);
                }
            }
        });
    }

    //用户名变化
    $('#usernametext').keyup(function () {
        userNameCheck($(this).val());
    });

    //用户名检查
    function userNameCheck(username) {

        var patten1 = /^([0-9]|[a-z]|[A-Z]|_)+$/;
        var patten2 = /^([a-z]|[A-Z])/;
        var patten3 = /^.{6,15}$/;
        username.trim();

        if (!patten1.test(username)) {
            userNameWarn('用户名只允许字母、数字、下划线组成');
            return false;
        } else if (!patten2.test(username)) {
            userNameWarn('用户名首位只能为字母');
            return false;
        } else if (!patten3.test(username)) {
            userNameWarn('用户名长度应为6-15位');
            return false;
        } else {
            userNameWarn('')
            return true;
        }
    }

    //修改用户名错误
    function userNameWarn(msg) {
        if (msg) {
            $('#usernamewarn').html('<em></em>' + msg);
        } else {
            $('#usernamewarn').html('');
        }
    }

    function hsChangePassWord() {
        var t1 = 0
        $('#hsvp-textbtn').click(function () {
            t2 = Date.now();
            if (t2 - t1 > 60 * 1000) {
                t1 = Date.now();
                $.ajax({
                    url: "/usercenter-Accountcontrol-hs_sendphone",
                    type: "POST",
                    data: {
                        cellphone: $('#hsvp-phonenum').val(),
                    },
                    success: function (data) {
                        var obj = eval('(' + data + ')');
                        mo2_regTim();
                        dialog(obj);
                    }
                });
                if ($(this).hasClass('m2-userSettings-telSubmit')) {
                    $(this).removeClass('m2-userSettings-telSubmit');
                    $(this).addClass('m2-userSettings-telSubmit-disabled');
                    setTimeout(function () {
                        $('#hsvp-textbtn').removeClass('m2-userSettings-telSubmit-disabled');
                        $('#hsvp-textbtn').addClass('m2-userSettings-telSubmit');
                    }, 60000);
                }
            }
        });
        $('#hsChange-btn').click(function () {
            var hsvp_phonenum = $("#hsvp-phonenum").val();
            var hs_code = $("#hs_code").val();
            var hs_name = $("#hs_name").val();
            var hs_idCard = $("#hs_idCard").val();

            if ($user_type == 1) {
                var regu = /(^[0-9]{15}$)|([0-9]{17}([0-9]|X|x)$)/;
                var re = new RegExp(regu);
                if (!re.test(hs_idCard)) {
                    var obj = new Array();
                    obj['msg'] = "身份证格式不正确";
                    obj['status'] = 0;
                    dialog(obj);
                    return false;
                }
            }

            if (hs_code == "" || hs_name == "" || hs_idCard == "") {
                var obj = new Array();
                obj['msg'] = "您需要填写全部信息才能提交";
                obj['status'] = 0;
                dialog(obj);
                return;
            } else {

                $.ajax({
                    url: "usercenter-Accountcontrol-hs_changePassWord",
                    type: "POST",
                    dataType: "json",
                    data: {
                        hs_code: hs_code,
                        hs_name: hs_name,
                        hs_idCard: hs_idCard,
                        hsvp_phonenum: hsvp_phonenum
                    },
                    success: function (data) {
                        if (data.status == 3) {
                            window.location.href = "/cupdata-Capital-setting";
                        } else {
                            dialog(data);
                        }
                    }
                });
            }
        });

        // 注册倒计时
        var regTim = 60; //剩余时间
        function mo2_regTim() {
            if (regTim > 0) {
                $('#hsvp-textbtn').html(regTim + '秒后重新发送');
                regTim--;
                setTimeout(function () {
                    mo2_regTim();
                }, 1000);
            }
            else if (regTim <= 0) {
                regTim = 60;
                $('#hsvp-textbtn').removeClass('m2-userSettings-telSubmit-disabled');
                $('#hsvp-textbtn').addClass('m2-userSettings-telSubmit');
                //$('.mo2-indRegtim').addClass('mo2-regTin-able').removeClass('mo2-regTin-unable');
                $('#hsvp-textbtn').html('重新发送');
            }
        }


    }
</script>
<script type="text/javascript">
    $(function () {
        //初始化省级下拉框
        var str = "";
        for (var i = 0; i < china.length; i++) {
            str += "<option data=" + i + ">" + china[i].name + "</option>";
        }
        $("#lmkselect1").append(str);

        //省级下拉框的change事件
        $("#lmkselect1").change(function () {
            $("#lmkselect2").attr("disabled", false);
            $("#lmkselect3").attr("disabled", true);
            var data = $("#lmkselect1").find("option:selected").attr("data");
            $("#lmkselect2 option:not(.all),#lmkselect3 option:not(.all)").remove();
            if (data == "all") {
                $("#lmkselect2,#lmkselect3").attr("disabled", true);
            } else {
                data = parseInt(data);
                str = "";
                for (var i = 0; i < china[data].city.length; i++) {
                    str += "<option data=" + i + " provice=" + data + ">" + china[data].city[i].name + "</option>";
                }
                $("#lmkselect2").append(str);
            }

        });
        //市级下拉框的事件
        $("#lmkselect2").change(function () {
            $("#lmkselect3").attr("disabled", false);
            var data = $("#lmkselect2").find("option:selected").attr("data");
            var provice = parseInt($("#lmkselect2").find("option:selected").attr("provice"));
            $("#lmkselect3 option:not(.all)").remove();
            if (data == "all") {
                $("#lmkselect3").attr("disabled", true);
            } else {
                data = parseInt(data);
                str = "";
                for (var i = 0; i < china[provice].city[data].area.length; i++) {
                    str += "<option>" + china[provice].city[data].area[i] + "</option>";
                }
                $("#lmkselect3").append(str);
            }
        });
        //初始化默认值
        var provice = "";
        var city = "";
        var area = "";
        if (provice != "") {
            // 循环省
            for (var i = 0; i < china.length; i++) {
                if (china[i].name == provice) {
                    $("#lmkselect1 option[data=" + i + "]").attr("selected", true);
                    //循环得到市
                    str = "";
                    for (var j = 0; j < china[i].city.length; j++) {
                        if (china[i].city[j].name == city) {
                            str += "<option data=" + j + " provice=" + i + " selected>" + china[i].city[j].name + "</option>";
                        } else {
                            str += "<option data=" + j + " provice=" + i + ">" + china[i].city[j].name + "</option>";
                        }
                    }
                    $("#lmkselect2").append(str);
                    //循环得到区
                    str = "";
                    var data = parseInt($("#lmkselect2").find("option:selected").attr("data"));
                    for (var j = 0; j < china[i].city[data].area.length; j++) {
                        if (china[i].city[data].area[j] == area) {
                            str += "<option selected>" + china[i].city[data].area[j] + "</option>";
                        } else {
                            str += "<option>" + china[i].city[data].area[j] + "</option>";
                        }
                    }
                    $("#lmkselect3").append(str);
                    $("#lmkselect2,#lmkselect3").attr("disabled", false);
                    return false;
                }
            }
        }
    })
</script>
</body>
</html>